export class AjaxMsg {
    constructor(data, domMap = {}){
        this._data = data;
        this._domMap = domMap;

        if(typeof this._data.data == 'object'){
            this.data = this._data.data;
        } else {
            this.data = {};
        }

        if(typeof this._data.status == 'number'){
            this.status = this._data.status;
        } else {
            this.status = 0;
        }

        if(typeof this._data.location == 'string'){
            this.location = this._data.location;
        } else {
            this.location = null;
        }
    }

    /**
     * 显示所有提示消息
     */
    showMsg(){
        if(this._data.msg instanceof Array){
            this._data.msg.forEach((data) => {
                $.toaster({
                    priority: data[0],
                    title: data[2],
                    message: data[3],
                    settings: {
                        timeout: 5000,
                    },
                });
            });
        }
    }

    /**
     * 显示验证提示
     * @param {Object} form - 表单
     */
    showFocus(form){
        console.log(form);
        if(this._data.focus instanceof Array){
            this._data.focus.forEach((data) => {
                let [isValid, name, info] = data;
                let propName = name + 'Input';
                if(propName in form && typeof form[propName].setValidation === 'function'){
                    form[propName].setValidation(isValid, info);
                }
            });
        }
    }
}